//
//  LGMedicineStatisticAlertView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/6/27.
//

#import "LGMedicineStatisticAlertView.h"

#define itemWidth   viewPix(320)
#define itemHeight  viewPix(56)

@interface LGMedicineStatisticAlertView()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *subTitleLabel;
/**   */
@property (nonatomic , strong)UIButton *completeBtn;
/**   */
@property (nonatomic , strong)UIButton *neverButton;
/**   */
@property (nonatomic , strong)UIButton *otherButton;
/**   */
@property (nonatomic , strong)UIView *lineView1;
/**   */
@property (nonatomic , strong)UIView *lineView2;
/**   */
@property (nonatomic , strong)UIView *lineView3;

@end

@implementation LGMedicineStatisticAlertView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeViewAnimation)]];
        self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0];
        [self addSubview:self.baseView];
        [self createSubView];
        [UIView animateWithDuration:0.4 animations:^{
            self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0.5];
            self.baseView.transform = CGAffineTransformScale(self.baseView.transform, 10000, 10000);
        }];
    }
    return self;
}

-(void)closeViewAnimation{
    [UIView animateWithDuration:0.4 animations:^{
        self.backgroundColor = [UIColor colorWithString:@"#000000" alpha:0];
        self.baseView.transform = CGAffineTransformScale(self.baseView.transform, 0.0001, 0.0001);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

-(void)completeBtnAction{
    if(self.selectCondition){
        self.selectCondition(@"-1");
    }
    [self closeViewAnimation];
}

-(void)neverButtonAction{
    if(self.selectCondition){
        self.selectCondition(@"-2");
    }
    [self closeViewAnimation];
}

-(void)otherButtonAction{
    if(self.selectCondition){
        self.selectCondition(@"other");
    }
    [self closeViewAnimation];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc]initWithFrame:CGRectMake((Screen_W-itemWidth)/2.0, (Screen_H-viewPix(224))/2.0, itemWidth, viewPix(224))];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 8;
        _baseView.transform = CGAffineTransformScale(_baseView.transform, 0.0001, 0.0001);
    }
    return _baseView;
}

-(void)createSubView{
    UILabel *titleLabel = [UILabel lableWithText:@"选择实际用药情况" colorString:@"#333333" textFont:LGFontWeight(17, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
    titleLabel.frame = CGRectMake(0, 0, itemWidth, itemHeight);
    [self.baseView addSubview:titleLabel];
    UIButton *completeBtn = [UIButton buttonWithTitle:@"完全按医嘱" titleFont:LGFont(17) textColor:@"#333333" imageName:@""];
    completeBtn.frame = CGRectMake(0, viewPix(56), itemWidth, itemHeight);
    [completeBtn addTarget:self action:@selector(completeBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.baseView addSubview:completeBtn];
    
    UIButton *neverButton = [UIButton buttonWithTitle:@"停药" titleFont:LGFont(17) textColor:@"#333333" imageName:@""];
    neverButton.frame = CGRectMake(0, viewPix(112), itemWidth, itemHeight);
    [neverButton addTarget:self action:@selector(neverButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.baseView addSubview:neverButton];
    
    UIButton *otherButton = [UIButton buttonWithTitle:@"其他用药情况" titleFont:LGFont(17) textColor:@"#333333" imageName:@""];
    otherButton.frame = CGRectMake(0, viewPix(168), itemWidth, itemHeight);
    [otherButton addTarget:self action:@selector(otherButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.baseView addSubview:otherButton];
    
    UIView *lineView1 = [[UIView alloc]initWithFrame:CGRectMake(0, kMinY(completeBtn.frame), itemWidth, 0.5)];
    lineView1.backgroundColor = [UIColor colorWithString:@"#E5E5E5"];
    [self.baseView addSubview:lineView1];
    
    UIView *lineView2 = [[UIView alloc]initWithFrame:CGRectMake(0, kMinY(neverButton.frame), itemWidth, 0.5)];
    lineView2.backgroundColor = [UIColor colorWithString:@"#E5E5E5"];
    [self.baseView addSubview:lineView2];
    
    UIView *lineView3 = [[UIView alloc]initWithFrame:CGRectMake(0, kMinY(otherButton.frame), itemWidth, 0.5)];
    lineView3.backgroundColor = [UIColor colorWithString:@"#E5E5E5"];
    [self.baseView addSubview:lineView3];
}



@end
